﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;

namespace Mario.Structures
{
    class FireBall
    {
        const int MAX_DISTANCE = 200;
        Vector2 StartPosition { get; set; }
        public Vector2 Speed { get; set; }
        public int Direction { get; set; }
        Vector2 Origin { get; set; }
        private Vector2 position;
        public Vector2 Position
        {
            set
            {
                position = value;
                StartPosition = value;
            }
            get
            {
                return position;
            }
        }
        public bool Visible { get; set; }
        private Animation.Animation idleAnimation;
        private SpriteEffects flip = SpriteEffects.None;
        private Animation.AnimationPlayer sprite;
        public Level Level
        {
            get { return level; }
        }
        Level level;
        public Circle BoundingCircle
        {
            get
            {
                return new Circle(Position, Tile.Width / 2.0f);
            }
        }
        public FireBall(Level level)
        {
            this.level = level;
            this.Visible = false;
            LoadContent();
        }
        public FireBall(Level level, Vector2 position,Vector2 speed,int direction,Boolean visible)
        {
            this.level = level;
            this.Speed = speed;
            this.Direction = direction;
            this.StartPosition = position;
            this.Position = StartPosition;
            this.Visible = visible;
            LoadContent();
        }
        public void LoadContent()
        {
            idleAnimation = new Animation.Animation(Level.Content.Load<Texture2D>("Tiles/Powerups/fball"), 0.1f, true);
            Origin = new Vector2(idleAnimation.FrameWidth / 2.0f, idleAnimation.FrameHeight / 2.0f);
            //collectedSound = Level.Content.Load<SoundEffect>("Sounds/coin");
        }
        public void Update(GameTime gameTime)
        {
            if (Vector2.Distance(StartPosition, Position) > MAX_DISTANCE)
            {
                this.Visible = false;
            }
            if (Visible == true)
            {
                //this.Position += speed * direction;
                Vector2 po = Speed;
                po.X = po.X * Direction;
                this.position += po;
            }
            sprite.PlayAnimation(idleAnimation);
        }
        public void OnHit(Player hitBy)
        {
            
        }
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            if(this.Visible)
            sprite.Draw(gameTime, spriteBatch, Position, flip);
            //spriteBatch.Draw(texture, Position, null, Color, 0.0f, origin, 1.0f, SpriteEffects.None, 0.0f);
        }
       

        

    }
}
